package com.zlf.service;

import com.zlf.mapper.FoodMapper;
import com.zlf.po.Food;
import com.zlf.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodServiceImpl implements FoodService {

    @Autowired
    private FoodMapper foodMapper;
    @Override
    public List<Food> listFoodByBusinessId(Integer businessId) {
        return foodMapper.listFoodByBusinessId(businessId);
    }

    @Override
    public int addFood(Food food) {
        return foodMapper.addFood(food);
    }

    @Override
    public int updateFood(Food food) {
        Food food1=foodMapper.getFoodById(food.getFoodId());
        if(food.getFoodName()!=null){
            food1.setFoodName(food.getFoodName());
        }
        if(food.getFoodExplain()!=null){
            food1.setFoodExplain(food.getFoodExplain());
        }
        if(food.getFoodPrice()!=null){
            food1.setFoodPrice(food.getFoodPrice());
        }
        return foodMapper.updateFood(food1);
    }
    @Override
    public int deleteFood(Integer foodId){
        Food food = foodMapper.getFoodById(foodId);

        return foodMapper.deleteFood(foodId);
    }
}
